from drf_yasg import openapi
from .serializers import *
CategoryViewsetDocs={
     'list': {
        'operation_description': "获取分类列表",
        'responses': {
            200: openapi.Response('分类详细信息')
        }
    },
    'choices':{
        'operation_description': "获取分类选择项（用于前端下拉框）",
        'responses': {
            200: openapi.Response('分类选择项')
        }
    },
    'roots':{
        'operation_description': "获取根分类列表",
       'responses': {
            200: openapi.Response('根分类列表')
        }
    },
    'children':{
        'operation_description': "获取指定分类的子分类列表",
       'responses': {
            200: openapi.Response('子分类列表')
    }
    },
    'products':{
        'operation_description': "获取指定分类下的商品列表",
        'responses': {
            200: openapi.Response('商品列表')
        }
    }
}

SellerViewsetDocs={
    'list':{
        'operation_description': "获取当前用户的商品列表",
        'manual_parameters': [
            openapi.Parameter(
                'status',
                openapi.IN_QUERY,
                description="商品状态筛选：草稿/发布/待发货/已发货/all",
                type=openapi.TYPE_STRING,
                enum=['draft', 'published','all']
            )
        ],
        'responses': {
            200: SellerProductSerializer(many=True),
            401: "未认证用户"
        }
    },
    'retrieve':{
        'operation_description': "获取商品详情",
        'responses': {
            200: SellerProductSerializer(),
            404: "商品不存在"
        }
    },

'create': {
        'operation_description': "创建商品（草稿/发布）",
        'request_body': openapi.Schema(
            type=openapi.TYPE_OBJECT,
            required=['name', 'price', 'category', 'delivery_method', 'delivery_location'],
            properties={
                'name': openapi.Schema(type=openapi.TYPE_STRING, description='商品名称'),
                'price': openapi.Schema(type=openapi.TYPE_NUMBER, description='商品价格'),
                'category': openapi.Schema(type=openapi.TYPE_INTEGER, description='分类ID'),
                'description': openapi.Schema(type=openapi.TYPE_STRING, description='商品描述'),
                'delivery_method': openapi.Schema(
                    type=openapi.TYPE_INTEGER,
                    description='发货方式: 0(包邮)/1(按距离计费)/2(一口价)/3(无需邮寄)',
                    enum=[0, 1, 2, 3]
                ),
                'delivery_location': openapi.Schema(
                    type=openapi.TYPE_STRING,
                    description='发货地，如"北京市海淀区"'
                ),
                'images': openapi.Schema(
                    type=openapi.TYPE_ARRAY,
                    items=openapi.Schema(
                        type=openapi.TYPE_OBJECT,
                        properties={
                            'image_url': openapi.Schema(type=openapi.TYPE_STRING, example="image_key.jpg"),
                            'display_order': openapi.Schema(type=openapi.TYPE_INTEGER, example=0)
                        }
                    )
                ),
                'action': openapi.Schema(
                    type=openapi.TYPE_STRING,
                    description='操作类型: publish(发布)或空(保存为草稿)',
                    enum=['publish', '']
                )
            }
        ),
        'responses': {
            201: SellerProductSerializer(),
            400: "参数错误",
            401: "未认证用户"
        }
    },
'destroy': {
        'operation_description': "删除商品",
        'responses': {
            204: "删除成功",
            404: "商品不存在"
        }
    },
'update': {
        'operation_description': "更新商品（草稿/发布）",
        'request_body': openapi.Schema(
            type=openapi.TYPE_OBJECT,
            properties={
                'name': openapi.Schema(type=openapi.TYPE_STRING, description='商品名称'),
                'price': openapi.Schema(type=openapi.TYPE_NUMBER, description='商品价格'),
                'category': openapi.Schema(type=openapi.TYPE_INTEGER, description='分类ID'),
                'description': openapi.Schema(type=openapi.TYPE_STRING, description='商品描述'),
                'delivery_method': openapi.Schema(
                    type=openapi.TYPE_INTEGER,
                    description='发货方式: 0(包邮)/1(按距离计费)/2(一口价)/3(无需邮寄)',
                    enum=[0, 1, 2, 3]
                ),
                'delivery_location': openapi.Schema(
                    type=openapi.TYPE_STRING,
                    description='发货地，如"北京市海淀区"'
                ),
                'images': openapi.Schema(
                    type=openapi.TYPE_ARRAY,
                    items=openapi.Schema(
                        type=openapi.TYPE_OBJECT,
                        properties={
                            'image_url': openapi.Schema(type=openapi.TYPE_STRING, example="image_key.jpg"),
                            'display_order': openapi.Schema(type=openapi.TYPE_INTEGER, example=0)
                        }
                    )
                ),
                'action': openapi.Schema(
                    type=openapi.TYPE_STRING,
                    description='操作类型: publish(发布)或空(保存为草稿)',
                    enum=['publish', '']
                )
            }
        ),
        'responses': {
            200: SellerProductSerializer(),
            400: "参数错误",
            404: "商品不存在"
        }
    },
'unpublish': {
    'operation_description': "下架商品（状态变为2）",
    'responses': {
        200: openapi.Response(
            description="下架成功",
            schema=openapi.Schema(
                type=openapi.TYPE_OBJECT,
                properties={
                    'status': openapi.Schema(type=openapi.TYPE_INTEGER)
                }
            )
        ),
        403: "无权操作",
        404: "商品不存在"
    }
},
'republish': {
    'operation_description': "重新上架商品（状态变为1）",
    'responses': {
        200: openapi.Response(
            description="上架成功",
            schema=openapi.Schema(
                type=openapi.TYPE_OBJECT,
                properties={
                    'status': openapi.Schema(type=openapi.TYPE_INTEGER)
                }
            )
        ),
        404: "商品不存在"
    }
},
'price':{
    'operation_description': "修改商品价格",
    'request_body': openapi.Schema(
        type=openapi.TYPE_OBJECT,
        required=['new_price'],
        properties={
            'new_price': openapi.Schema(type=openapi.TYPE_NUMBER, description='新的商品价格')
        }
    ),
    'responses': {
        200: openapi.Response(
            description="修改成功",
            schema=openapi.Schema(
                type=openapi.TYPE_OBJECT,
                properties={
                'message': openapi.Schema(type=openapi.TYPE_STRING, default='降价成功'),
                'old_price': openapi.Schema(type=openapi.TYPE_NUMBER, description='旧的商品价格'),
                'new_price': openapi.Schema(type=openapi.TYPE_NUMBER, description='新的商品价格')
                }
            )
        ),
        404: "商品不存在"
    }
}


}


BuyerViewsetDocs = {
    'list': {
        'operation_description': "获取商品列表",
        'manual_parameters': [
            openapi.Parameter(
                'category',
                openapi.IN_QUERY,
                description="分类ID",
                type=openapi.TYPE_INTEGER,
                required=False
            ),
            openapi.Parameter(
                'search',
                openapi.IN_QUERY,
                description="搜索关键词",
                type=openapi.TYPE_STRING,
                required=False
            ),
            openapi.Parameter(
                'order_by',
                openapi.IN_QUERY,
                description="排序方式：price_asc(价格升序)/price_desc(价格降序)/create_time(创建时间)",
                type=openapi.TYPE_STRING,
                enum=['price_asc', 'price_desc', 'create_time'],
                required=False
            )
        ],
        'responses': {
            200: BuyerProductSerializer(many=True)
        }
    },
    'retrieve': {
        'operation_description': "获取商品详情",
        'responses': {
            200: BuyerProductSerializer(),
            404: "商品不存在"
        }
    },

'search': {
    'operation_description': "搜索商品",
    'manual_parameters': [
        openapi.Parameter(
            'q',
            openapi.IN_QUERY,
            description="搜索关键词",
            type=openapi.TYPE_STRING,
            required=False
        ),
        openapi.Parameter(
            'category',
            openapi.IN_QUERY,
            description="分类ID",
            type=openapi.TYPE_INTEGER,
            required=False
        )
    ],
    'responses': {
        200: BuyerProductSerializer(many=True)
    }
},
'favorites':  {
        'POST': {
            'operation_description': "收藏商品",
            'responses': {
                201: openapi.Response(
                    description="收藏成功",
                    schema=openapi.Schema(
                        type=openapi.TYPE_OBJECT,
                        properties={
                            'status': openapi.Schema(type=openapi.TYPE_STRING),
                            'message': openapi.Schema(type=openapi.TYPE_STRING)
                        }
                    )
                ),
                400: "商品已收藏",
                401: "用户未登录"
            }
        },
        'DELETE': {
            'operation_description': "取消收藏",
            'responses': {
                200: openapi.Response(
                    description="取消收藏成功",
                    schema=openapi.Schema(
                        type=openapi.TYPE_OBJECT,
                        properties={
                            'status': openapi.Schema(type=openapi.TYPE_STRING),
                            'message': openapi.Schema(type=openapi.TYPE_STRING)
                        }
                    )
                ),
                404: "商品未收藏",
                401: "用户未登录"
            }
        }
    },
'favorites_list':{
    'operation_description': "获取用户收藏的商品列表",
   'responses': {
        200: BuyerProductSerializer(many=True),
        401: "未认证用户"
    }
}
}